package com.t2t.top.log;


import org.apache.commons.lang.StringUtils;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

import java.util.UUID;

/**
 * Created by yangpengfei on 2015/2/3
 */
@Component
@Aspect
public class LogTraceAdvice {

    Logger logger = LoggerFactory.getLogger(this.getClass());

    @Around("@annotation(com.t2t.top.log.LogTrace)")
    public Object around(ProceedingJoinPoint pjp) throws Throwable {
        try {
            if (LogSessionUtils.isNotBind()) {
                LogSessionUtils.bind(UUID.randomUUID().toString());
            }
            return pjp.proceed();
        } finally {
            LogSessionUtils.remove();
        }
    }

    private String parseShortClassName(String className) {
        return StringUtils.substringAfterLast(className, ".");
    }
}
